package com.soft.controller;

import com.soft.pojo.Jianli;
import com.soft.pojo.PageBean;
import com.soft.service.EmpRecordService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ruoxi
 * @create 2021-12-27 10:51
 */
@WebServlet("/showEmpRecordByPage")
public class ShowEmpRecordByPageServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        EmpRecordService empRecordService = new EmpRecordService();
        PageBean<Jianli> empRecordPg = new PageBean<>();

        int currentPage = 1;
        String currentPage_ = req.getParameter("currentPage");
        if (currentPage_ != null) {
            currentPage = Integer.parseInt(currentPage_);
        }

        int currentCount = 10;

        empRecordPg.setCurrentPage(currentPage);
        empRecordPg.setCurrentCount(currentCount);
        empRecordPg.setTotalCount(empRecordService.findEmpRecordCount());
        empRecordPg.setTotalPage((int) Math.ceil(empRecordService.findEmpRecordCount() * 1.0 / currentCount));
        empRecordPg.setList(empRecordService.findEmpRecordByPage((currentPage - 1) * currentCount, currentCount));

        req.setAttribute("empRecordPg", empRecordPg);
        req.getRequestDispatcher("emprecord.jsp").forward(req, resp);
    }
}
